package com.sky.city.mvp;

import com.common.baselibrary.mvp.BasePresenter;
import com.common.baselibrary.request.ConfigConstant;
import com.common.baselibrary.request.RequestBean;
import com.common.baselibrary.util.ToastToolsHelper;
import com.google.gson.Gson;
import com.sky.city.bean.LoginBean;
import com.sky.city.request.RequestManager;

import okhttp3.RequestBody;

public class LoginPrecenter extends BasePresenter<LoginConstract.LoginView> {
    public void login(RequestBody requestBody){
        RequestManager.login(getView().getContext(), requestBody, new RequestManager.OnResponseListener() {
            @Override
            public void onSuccess(Object object) {
                try {
                    RequestBean requestBean=new Gson().fromJson(object.toString(),RequestBean.class);
                    if(requestBean.getCode()!= ConfigConstant.Config.SUCCESSCODE){
                        ToastToolsHelper.show(requestBean.getMsg());
                        getView().LoginFailerd(requestBean.getMsg());
                        return;
                    }
                    LoginBean loginBean=new Gson().fromJson(object.toString(), LoginBean.class);
                    getView().LoginSucess(loginBean);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailre(String msg) {

            }
        });
    }
}
